<?php
namespace App\Api\Controllers\Qwx;


use Alipayopen\Sdk\AopClient;
use Alipayopen\Sdk\Request\AlipayTradePayRequest;
use App\Api\Controllers\Config\AlipayIsvConfigController;
use App\Api\Controllers\Config\EasyPayConfigController;
use App\Api\Controllers\Config\HConfigController;
use App\Api\Controllers\Config\HkrtConfigController;
use App\Api\Controllers\Config\HuiPayConfigController;
use App\Api\Controllers\Config\HwcPayConfigController;
use App\Api\Controllers\Config\JdConfigController;
use App\Api\Controllers\Config\LianfuConfigController;
use App\Api\Controllers\Config\NongjinConfigController;
use App\Api\Controllers\Config\LinkageConfigController;
use App\Api\Controllers\Config\LtfConfigController;
use App\Api\Controllers\Config\PinganConfigController;
use App\Api\Controllers\Config\MyBankConfigController;
use App\Api\Controllers\Config\NewLandConfigController;
use App\Api\Controllers\Config\SaobeiConfigController;
use App\Api\Controllers\Config\JiuJiangConfigController;
use App\Api\Controllers\Config\LianfuyoupayConfigController;
use App\Api\Controllers\Config\PayWaysController;
use App\Api\Controllers\Config\WingConfigController;
use App\Api\Controllers\Config\TfConfigController;
use App\Api\Controllers\Config\VbillConfigController;
use App\Api\Controllers\Config\WeixinConfigController;
use App\Api\Controllers\Config\WftPayConfigController;
use App\Api\Controllers\DuoLaBao\ManageController;
use App\Api\Controllers\EasyPay\PayController;
use App\Api\Controllers\Linkage\PayController as LinkAgePayController;
use App\Api\Controllers\HwcPay\PayController as HwcpayPayController;
use App\Api\Controllers\WftPay\PayController as WftpayPayController;
use App\Api\Controllers\MyBank\TradePayController;
use App\Common\MerchantFuwu;
use App\Common\PaySuccessAction;
use App\Common\StoreDayMonthOrder;
use App\Common\UserGetMoney;
use App\Models\AlipayAccount;
use App\Models\MyBankStore;
use App\Models\Order;
use App\Models\OrderItem;
use App\Models\QwxStore;
use App\Models\Store;
use App\Models\StorePayWay;
use App\Services\Pay\GuoTonXinYi\BizService;
use App\Services\Pay\PayService;
use EasyWeChat\Factory;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;

class TradepayTwoController extends \App\Api\Controllers\BaseController
{

    //2.0配合微收银的扫一扫
    public function scan_pay($data)
    {
        try {
            $store_id = $data['store_id'];
            $code = $data['code'];
            $total_amount = $data['total_amount'];
            $shop_price = $data['shop_price'];
            $remark = $data['remark'];
            $device_id = $data['device_id'];
            $shop_name = $data['shop_name'];
            $shop_desc = $data['shop_desc'];
            $qwx_no = $data['qwx_no'];
            $pay_method = isset($data['pay_method']) ? $data['pay_method'] : "qr_code";

            $store = Store::where('store_id', $store_id)
                ->select("store_address",'config_id', 'store_name', 'pid', 'user_id')
                ->first();

            //app
            if ($device_id == 'app') {
                $merchant_id = $data['merchant_id'];
                $merchant_name = $data['merchant_name'];
            } else {
                //微收银终端
                $QwxStore = QwxStore::where('device_id', $device_id)
                    ->select('merchant_id', 'merchant_name')
                    ->first();
                $merchant_id = "1";
                $merchant_name = "收银员";
                if ($QwxStore) {
                    $merchant_id = $QwxStore->merchant_id;
                    $merchant_name = $QwxStore->merchant_name;
                }
            }
            
            $store = Store::where('store_id', $store_id)
                ->select("status","store_address",'config_id', 'store_name', 'pid', 'user_id', 'is_delete', 'is_admin_close', 'is_close','state')
                ->first();
            if (!$store) {
                return json_encode([
                    'status' => 2,
                    'message' => '没有关联认证门店请联系服务商'
                ]);
            }
	    
            //关闭的商户禁止交易
            if ($store->is_close || $store->is_admin_close || $store->is_delete || $store->state==3) {
                return json_encode([
                    'status' => 2,
                    'message' => '商户已经被服务商关闭'
                ]);
            }

            if($store->status!=1){
                return json_encode([
                    'status' => '2',
                    'message' => '商户已经被服务商关闭,请联系客服'
                ]);
            }


            if($store->pid>0){
                $p1_store=DB::table('stores')->where('id', $store->pid)->select('store_name', 'config_id', 'pid', 'user_id', 'is_admin_close', 'is_delete', 'alipay_account', 'is_close','state')->first();
                if($p1_store->state==3){
                    return json_encode([
                        'status' => 2,
                        'message' => '商户已经关闭'
                    ]);
                }
            }

            $config_id = $store->config_id;
            $store_name = $store->store_name;
            $store_pid = $store->pid;
            $tg_user_id = $store->user_id;

            //插入数据库
            $data_insert = [
                'trade_no' => '',
                'qwx_no' => $qwx_no,
                'user_id' => $tg_user_id,
                'store_id' => $store_id,
                'store_name' => $store_name,
                'buyer_id' => '',
                'total_amount' => $total_amount,
                'pay_amount' => $total_amount,
                'shop_price' => $shop_price,
                'payment_method' => '',
                'status' => '',
                'pay_status' => 2,
                'pay_status_desc' => '等待支付',
                'merchant_id' => $merchant_id,
                'merchant_name' => $merchant_name,
                'remark' => $remark,
                'device_id' => $device_id,
                'config_id' => $config_id,
                'pay_method' => $pay_method,
                'auth_code' => $code
            ];

            $str = substr($code, 0, 2);

            /**支付宝渠道开始**/
            if ($str == "25" || $str == "26" || $str == "27" || $str == "28" || $str == "29" || $str == "30") {
                //读取优先为高级的通道
                $obj_ways = new PayWaysController(['total_amount' => $total_amount]);
                $ways = $obj_ways->ways_source('alipay', $store_id, $store_pid);

                $out_trade_no = date('YmdHis', time()) . substr(microtime(), 2, 6) . sprintf('%03d', rand(0, 999));
                if (!$ways) {
                    $msg = '此类型通道没有开通';
                    return [
                        'status' => 2,
                        'message' => $msg
                    ];

                }
                //验证扣费模式
                list($isRun,$error)=\App\Services\Store\StoreSignService::validateSign((string)$ways->store_id,(string)$ways->company);
                if($isRun==false){
                    return json_encode([
                        'status' => 2,
                        'message' => $error
                    ]);
                }


                $data_insert ['rate'] = $ways->rate;
                $data_insert['fee_amount'] = $ways->rate * $total_amount / 100;

                //官方支付宝扫一扫
                if ($ways && $ways->ways_type == 1000) {
                    $data['out_trade_no'] = $out_trade_no;
                    //入库参数
                    $data_insert['out_trade_no'] = $out_trade_no;
                    $data_insert['ways_type'] = $ways->ways_type;
                    $data_insert['company'] = $ways->company;
                    $data_insert['ways_type_desc'] = '支付宝';
                    $data_insert['ways_source'] = 'alipay';
                    $data_insert['ways_source_desc'] = '支付宝';

                    $config_type = '01';


                    //配置
                    $isvconfig = new AlipayIsvConfigController();
                    $storeInfo = $isvconfig->alipay_auth_info($store_id, $store_pid);
                    $out_user_id = $storeInfo->user_id;//商户的id
                    $alipay_store_id = $storeInfo->alipay_store_id;


                    //分成模式 服务商
                    if ($storeInfo->settlement_type == "set_a") {
                        if ($storeInfo->config_type == '02') {
                            $config_type = '02';
                        }
                        $storeInfo = AlipayAccount::where('config_id', $config_id)
                            ->where('config_type', $config_type)
                            ->first();//服务商的
                    }

                    if (!$storeInfo) {
                        $msg = '支付宝授权信息不存在';
                        return [
                            'status' => 2,
                            'message' => $msg
                        ];

                    }

                    $app_auth_token = $storeInfo->app_auth_token;
                    $out_store_id = $storeInfo->out_store_id;

                    $config = $isvconfig->AlipayIsvConfig($config_id, $config_type);


                    $insert_re = $this->insert_day_order($data_insert);

                    if (!$insert_re) {
                        return json_encode([
                            'status' => 2,
                            'message' => '订单未入库'
                        ]);
                    }


                    $notify_url = url('/api/alipayopen/qr_pay_notify');
                    $disable_pay_channels = '';//仅用方式
                    $aop = new AopClient();
                    $aop->apiVersion = "2.0";
                    $aop->appId = $config->app_id;
                    $aop->rsaPrivateKey = $config->rsa_private_key;
                    $aop->alipayrsaPublicKey = $config->alipay_rsa_public_key;
                    $aop->method = 'alipay.trade.pay';
                    // $aop->notify_url = $notify_url;
                    $aop->signType = "RSA2";//升级算法
                    $aop->gatewayUrl = $config->alipay_gateway;
                    $aop->format = "json";
                    $aop->charset = "GBK";
                    $aop->version = "2.0";


                    $requests = new AlipayTradePayRequest();
                    // $requests->setNotifyUrl($notify_url);
                    //提交到支付宝
                    if ($alipay_store_id) {
                        $data_re = "{" .
                            "\"out_trade_no\":\"" . $out_trade_no . "\"," .
                            "\"seller_id\":\"" . $out_user_id . "\"," .//商户收款账号
                            "\"disable_pay_channels\":\"" . $disable_pay_channels . "\"," .
                            "    \"scene\":\"bar_code\"," .
                            "    \"auth_code\":\"" . $code . "\"," .
                            "    \"subject\":\"" . $shop_name . "\"," .
                            "    \"total_amount\":" . $total_amount . "," .
                            "    \"timeout_express\":\"90m\"," .
                            "    \"body\":\"" . $shop_desc . "\"," .
                            "      \"goods_detail\":[{" .
                            "        \"goods_id\":\"" . $store_id . "\"," .
                            "        \"goods_name\":\"" . $shop_name . "\"," .
                            "        \"quantity\":1," .
                            "        \"price\":" . $total_amount . "," .
                            "        \"body\":\"" . $shop_name . "\"" .
                            "        }]," .
                            "    \"store_id\":\"" . $out_store_id . "\"," .
                            "    \"shop_id\":\"" . $alipay_store_id . "\"," .
                            "    \"terminal_id\":\"" . $device_id . "\"," .
                            "    \"operator_id\":\"D_001_" . $merchant_id . "\"," .
                            "    \"extend_params\":{" .
                            "      \"sys_service_provider_id\":\"" . $config->alipay_pid . "\"" .
                            "}" .
                            "  }";
                    } else {
                        $data_re = "{" .
                            "\"out_trade_no\":\"" . $out_trade_no . "\"," .
                            "\"seller_id\":\"" . $out_user_id . "\"," .//商户收款账号
                            "\"disable_pay_channels\":\"" . $disable_pay_channels . "\"," .
                            "    \"scene\":\"bar_code\"," .
                            "    \"auth_code\":\"" . $code . "\"," .
                            "    \"subject\":\"" . $shop_name . "\"," .
                            "    \"total_amount\":" . $total_amount . "," .
                            "    \"timeout_express\":\"90m\"," .
                            "    \"body\":\"" . $shop_desc . "\"," .
                            "      \"goods_detail\":[{" .
                            "        \"goods_id\":\"" . $store_id . "\"," .
                            "        \"goods_name\":\"" . $shop_name . "\"," .
                            "        \"quantity\":1," .
                            "        \"price\":" . $total_amount . "," .
                            "        \"body\":\"" . $shop_name . "\"" .
                            "        }]," .
                            "    \"store_id\":\"" . $store_id . "\"," .
                            "    \"terminal_id\":\"" . $device_id . "\"," .
                            "    \"operator_id\":\"D_001_" . $merchant_id . "\"," .
                            "    \"extend_params\":{" .
                            "      \"sys_service_provider_id\":\"" . $config->alipay_pid . "\"" .
                            "}" .
                            "  }";
                    }
                    //  dd($data_re);
                    $requests->setBizContent($data_re);
                    $result = $aop->execute($requests, null, $app_auth_token);

                    $responseNode = str_replace(".", "_", $requests->getApiMethodName()) . "_response";
                    $resultCode = $result->$responseNode->code;
                    //异常
                    if ($resultCode == 40004) {
                        return json_encode([
                            'status' => 2,
                            'message' => $result->$responseNode->msg . $result->$responseNode->sub_code,
                            'result_code' => $resultCode,
                        ]);
                    }
                    //支付成功
                    if (!empty($resultCode) && $resultCode == 10000) {
                        $buyer_id = $result->$responseNode->buyer_user_id;
                        $buyer_logon_id = $result->$responseNode->buyer_logon_id;
                        $payment_method = $result->$responseNode->fund_bill_list[0]->fund_channel;
                        $trade_no = $result->$responseNode->trade_no;
                        $gmt_payment = $result->$responseNode->gmt_payment;
                        $buy_pay_amount = $result->$responseNode->buyer_pay_amount;


                        $up_data = [
                            'trade_no' => $trade_no,
                            'buyer_id' => $buyer_id,
                            'buyer_logon_id' => $buyer_logon_id,
                            'status' => 'TRADE_SUCCESS',
                            'pay_status_desc' => '支付成功',
                            'pay_status' => 1,
                            'payment_method' => $payment_method,
                            'pay_time' => $gmt_payment,
                            'buyer_pay_amount' => $buy_pay_amount,
                        ];

                        $this->update_day_order($up_data, $out_trade_no);

                        //支付成功后的动作
                        $data = [
                            'ways_type' => $ways->ways_type,
                            'ways_type_desc' => $ways->ways_desc,
                            'company' => $ways->company,
                            'source_type' => '1000',//返佣来源
                            'source_desc' => '支付宝',//返佣来源说明
                            'total_amount' => $total_amount,
                            'out_trade_no' => $out_trade_no,
                            'rate' => $data_insert['rate'],
                            'merchant_id' => $merchant_id,
                            'store_id' => $store_id,
                            'user_id' => $tg_user_id,
                            'config_id' => $config_id,
                            'store_name' => $store_name,
                            'ways_source' => $ways->ways_source,
                            'fee_amount' => $data_insert['fee_amount'],
                            'pay_time' => $gmt_payment,
                            'no_push' => '1',//不推送
                            'no_fuwu' => '1',//不服务消息
//                            'no_print' => '1',//不打印
                            //'no_v' => '1',//不小盒子播报

                        ];


                        PaySuccessAction::action($data);

                        return json_encode([
                            'status' => 1,
                            'message' => '支付成功',
                            'data' => [
                                'out_trade_no' => $out_trade_no,
                                'out_transaction_id' => $out_trade_no,
                                'total_amount' => $total_amount,
                                'store_name' => $store_name,
                                'trade_no' => $trade_no,
                                'pay_time' => $gmt_payment,
                            ]
                        ]);


                    }
                    //正在支付
                    if (!empty($resultCode) && $resultCode == 10003) {
                        return json_encode([
                            'status' => 9,
                            'message' => '等待用户支付',
                            'data' => [
                                'out_trade_no' => $out_trade_no,
                                'total_amount' => $total_amount,
                                'store_name' => $store_name,
                            ]
                        ]);

                    }
                    $msg = $result->$responseNode->sub_msg;//错误信息
                    return json_encode([
                        'status' => 2,
                        'message' => $msg,
                    ]);
                }

                //京东收银支付宝扫一扫
                if ($ways && $ways->ways_type == 6001) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $store->user_id,
                    ];

                    return $this->jd_pay_public($data_insert, $data_public);

                }

                //联拓富收银支付宝扫一扫
                if ($ways && $ways->ways_type == 10001) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $store->user_id,
                    ];

                    return $this->ltf_pay_public($data_insert, $data_public);

                }

                //和融通收银支付宝
                if ($ways && $ways->ways_type == 9001) {
                    $data_public = [
                        'pay_type' => 'ali',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $store->user_id,
                    ];

                    return $this->h_pay_public($data_insert, $data_public);

                }

                //快钱支付宝支付宝扫一扫
                if ($ways && $ways->ways_type == 3001) {
                    $data_public = [
                        'pay_type' => 'alipay',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];
                    return $this->mybank_pay_public($data_insert, $data_public);
                }

                //新大陆支付宝
                if ($ways && $ways->ways_type == 8001) {
                    $config = new NewLandConfigController();
                    $new_land_config = $config->new_land_config($config_id);
                    if (!$new_land_config) {
                        return json_encode([
                            'status' => 2,
                            'message' => '新大陆配置不存在请检查配置'
                        ]);
                    }

                    $new_land_merchant = $config->new_land_merchant($store_id, $store_pid);
                    if (!$new_land_merchant) {
                        return json_encode([
                            'status' => 2,
                            'message' => '商户新大陆通道未开通'
                        ]);
                    }
                    $request_data = [
                        'out_trade_no' => $out_trade_no,
                        'code' => $code,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'key' => $new_land_merchant->nl_key,
                        'org_no' => $new_land_config->org_no,
                        'merc_id' => $new_land_merchant->nl_mercId,
                        'trm_no' => $new_land_merchant->trmNo,
                        'op_sys' => '3',
                        'opr_id' => $merchant_id,
                        'trm_typ' => 'T',
                        'payChannel' => 'ALIPAY',
                    ];

                    //入库参数
                    $data_insert['out_trade_no'] = $out_trade_no;
                    $data_insert['ways_type'] = $ways->ways_type;
                    $data_insert['ways_type_desc'] = '支付宝';
                    $data_insert['ways_source'] = $ways->ways_source;
                    $data_insert['ways_source_desc'] = '支付宝';
                    $data_insert['company'] = $ways->company;


                    return $this->newland_pay_public($data_insert, $request_data);
                }

                //随行付支付宝
                if ($ways && $ways->ways_type == 13001) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->vbill_pay_public($data_insert, $data_public);

                }

                //随行付A支付宝
                if ($ways && $ways->ways_type == 19001) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->vbilla_pay_public($data_insert, $data_public);

                }

                //哆啦宝支付宝
                if ($ways && $ways->ways_type == 15001) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->dlb_pay_public($data_insert, $data_public);

                }

                //传化支付宝
                if ($ways && $ways->ways_type == 12001) {
                    $data_public = [
                        'channel' => 'ALIPAY_POS',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->tf_pay_public($data_insert, $data_public);
                }

                //汇付支付宝
                if ($ways && $ways->ways_type == 18001) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->huipay_pay_public($data_insert, $data_public);
                }

                //工行支付宝
                if ($ways && $ways->ways_type == 20001) {
                    $data_public = [
                        'payment' => '2',
                        'goodsId' => time(),
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->lianfu_pay_public($data_insert, $data_public);
                }

                //农商行支付宝
                if ($ways && $ways->ways_type == 20802) {
                    $data_public = [
                        'payment' => '2',
                        'goodsId' => time(),
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->nongjin_pay_public($data_insert, $data_public);
                }
                
                //扫呗支付宝
                if ($ways && $ways->ways_type == 30081) {
                    $data_public = [
                        'payment' => '2',
                        'goodsId' => time(),
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->saobei_pay_public($data_insert, $data_public);
                }
                
                
                //平安银行支付宝
                if ($ways && $ways->ways_type == 30012) {
                    $data_public = [
                        'payment' => '2',
                        'goodsId' => time(),
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->pingan_pay_public($data_insert, $data_public);
                }
                
                //九江银行支付宝
                if ($ways && $ways->ways_type == 37002) {
                    $data_public = [
                        'payment' => '2',
                        'goodsId' => time(),
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->jiujiang_pay_public($data_insert, $data_public);
                }
                
                //邮储银行支付宝
                if ($ways && $ways->ways_type == 26001) {
                    $data_public = [
                        'payment' => '2',
                        'goodsId' => time(),
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->you_pay_public($data_insert, $data_public);
                }

                //海科融通 支付宝 被扫
                if ($ways && $ways->ways_type == 22001) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];
                    return $this->hkrt_pay_public($data_insert, $data_public);
                }

                //易生支付 支付宝 被扫
                if ($ways && $ways->ways_type == 21001) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                        "settlement_type"=>$ways->settlement_type ?? ''
                    ];

                    return $this->easypay_pay_public($data_insert, $data_public);
                }

                //联动优势 支付宝 被扫
                if ($ways && $ways->ways_type == 5001) {
                    $data_public = [
                        'orderType' => 'alipay',
                        'goodsId' => time(),
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id
                    ];

                    return $this->linkage_pay_public($data_insert, $data_public);
                }

                //威富通 支付宝
                if ($ways && $ways->ways_type == 27001) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->wft_pay_public($data_insert, $data_public);

                }
                
                 //威富通 支付宝
                if ($ways && $ways->ways_type == 30051) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->wing_pay_public($data_insert, $data_public);

                }

                //汇旺财 支付宝
                if ($ways && $ways->ways_type == 28001) {
                    $data_public = [
                        'pay_type' => 'ALIPAY',
                        'return_params' => '原样返回',
                        'title' => '支付宝收款',
                        'ways_source_desc' => '支付宝',
                        'ways_type_desc' => '支付宝',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->hwc_pay_public($data_insert, $data_public);

                }

            }
            /**支付宝渠道结束**/

            //微信渠道
            if ($str == "10" || $str == "11" || $str == "12" || $str == "13" || $str == "14" || $str == "15") {
                //读取优先为高级的通道
                $obj_ways = new PayWaysController(['total_amount' => $total_amount]);
                $ways = $obj_ways->ways_source('weixin', $store_id, $store_pid);

                if (!$ways) {
                    $msg = '此类型通道没有开通';
                    return [
                        'status' => 2,
                        'message' => $msg
                    ];

                }

                //验证扣费模式
                list($isRun,$error)=\App\Services\Store\StoreSignService::validateSign((string)$ways->store_id,(string)$ways->company);
                if($isRun==false){
                    return json_encode([
                        'status' => 2,
                        'message' => $error
                    ]);
                }

                $data_insert ['rate'] = $ways->rate;
                $data_insert['fee_amount'] = $ways->rate * $total_amount / 100;
                $out_trade_no =  date('YmdHis', time()) . substr(microtime(), 2, 6) . sprintf('%03d', rand(0, 999));

                //官方微信扫一扫
                if ($ways && $ways->ways_type == 2000) {

                    $config = new WeixinConfigController();
                    $options = $config->weixin_config($config_id);
                    $weixin_store = $config->weixin_merchant($store_id, $store_pid);
                    if (!$weixin_store) {
                        return json_encode([
                            'status' => 2,
                            'message' => '微信商户号不存在'
                        ]);
                    }
                    $wx_sub_merchant_id = $weixin_store->wx_sub_merchant_id;

                    $data_insert['out_trade_no'] = $out_trade_no;
                    $data_insert['ways_type'] = $ways->ways_type;
                    $data_insert['ways_type_desc'] = '微信支付';
                    $data_insert['ways_source'] = 'weixin';
                    $data_insert['company'] = $ways->company;
                    $data_insert['ways_source_desc'] = '微信支付';

                    $type = 2001;
                    $attach = $store_id . ',' . $config_id;//附加信息原样返回
                    $goods_detail = [];
                    //入库参数
                    $insert_re = $this->insert_day_order($data_insert);
                    if (!$insert_re) {
                        return json_encode([
                            'status' => 2,
                            'message' => '订单未入库'
                        ]);
                    }

                    $config = [
                        'app_id' => $options['app_id'],
                        'mch_id' => $options['payment']['merchant_id'],
                        'key' => $options['payment']['key'],
                        'cert_path' => $options['payment']['cert_path'], // XXX: 绝对路径！！！！
                        'key_path' => $options['payment']['key_path'],     // XXX: 绝对路径！！！！
                        'sub_mch_id' => $wx_sub_merchant_id,
                    ];
                    $payment = Factory::payment($config);

                    if ($weixin_store->wx_shop_id&&$weixin_store->wx_shop_id) {
//                        $goods_detail = [
//                            'goods_detail' => [
//                                [
//                                    'goods_id' => $weixin_store->wx_shop_id,
//                                    'quantity' => 1,
//                                    'price' => $total_amount * 100
//                                ]
//                            ]
//                        ];

                        $wx_shop_id = $weixin_store->wx_shop_id;
                        $wx_shop_id = explode(',', $wx_shop_id);
                        $goods_detail = [];
                        foreach ($wx_shop_id as $value) {
                            $goods_detail[] = [
                                'goods_id' => $value,
                                'quantity' => 1,
                                'price' => $total_amount * 100
                            ];
                        }

                        $goods_detail = [
                            'goods_detail' => $goods_detail
                        ];

                        $attributes = [
                            'version' => '1.0',
                            'body' => $shop_name,
                            'detail' => json_encode($goods_detail),
                            'out_trade_no' => $out_trade_no,
                            'total_fee' => $total_amount * 100,
                            'auth_code' => $code,
                            'attach' => $attach,//原样返回
                            'device_info' => $device_id,
                        ];
                    } else {
                        $attributes = [
                            'body' => $shop_name,
                            'detail' => $shop_desc,
                            'out_trade_no' => $out_trade_no,
                            'total_fee' => $total_amount * 100,
                            'auth_code' => $code,
                            'attach' => $attach,//原样返回
                            'device_info' => $device_id,
                            'goods_detail' => $goods_detail,//交易详细数据
                        ];
                    }

                    $result = $payment->pay($attributes);

                    //请求状态
                    if ($result['return_code'] == 'SUCCESS') {
                        //支付成功
                        if ($result['result_code'] == 'SUCCESS') {
                            $data_update = [
                                'receipt_amount' => 0,//商家实际收到的款项
                                'status' => $result['result_code'],
                                'pay_status' => 1,//系统状态
                                'pay_status_desc' => '支付成功',
                                'payment_method' => $result['bank_type'],
                                'buyer_id' => $result['openid'],
                                'trade_no' => $result['transaction_id'],
                            ];
                            $this->update_day_order($data_update, $out_trade_no);

                            if (!$insert_re) {
                                return json_encode([
                                    'status' => 2,
                                    'message' => '订单未入库'
                                ]);
                            }

                            //支付成功后的动作
                            $data = [
                                'ways_type' => $ways->ways_type,
                                'ways_type_desc' => $ways->ways_desc,
                                'company' => $ways->company,
                                'source_type' => '2000',//返佣来源
                                'source_desc' => '微信支付',//返佣来源说明
                                'total_amount' => $total_amount,
                                'out_trade_no' => $out_trade_no,
                                'rate' => $data_insert['rate'],
                                'fee_amount' => $data_insert['fee_amount'],
                                'merchant_id' => $merchant_id,
                                'store_id' => $store_id,
                                'user_id' => $tg_user_id,
                                'config_id' => $config_id,
                                'store_name' => $store_name,
                                'ways_source' => $ways->ways_source,
                                'pay_time' => $result['time_end'],
                                'no_push' => '1',//不推送
                                'no_fuwu' => '1',//不服务消息
//                                'no_print' => '1',//不打印
                                //'no_v' => '1',//不小盒子播报

                            ];


                            PaySuccessAction::action($data);

                            return json_encode([
                                'status' => 1,
                                'data' => [
                                    'out_trade_no' => $out_trade_no,
                                    'store_name' => $store_name,
                                    'trade_no' => $result['transaction_id'],
                                    'total_amount' => $total_amount,
                                    'pay_time' => $result['time_end'],
                                    'out_transaction_id' => $out_trade_no,
                                ]
                            ]);


                        } else {

                            if ($result['err_code'] == "USERPAYING") {
                                return json_encode([
                                    'status' => 9,
                                    'message' => '等待用户支付',
                                    'data' => [
                                        'out_trade_no' => $out_trade_no,
                                        'total_amount' => $total_amount,
                                        'store_name' => $store_name,
                                    ]
                                ]);

                            } else {
                                $msg = $result['err_code_des'];//错误信息
                                return json_encode([
                                    'status' => 2,
                                    'message' => $msg,
                                ]);
                            }


                        }


                    } else {
                        $data = [
                            'status' => 2,
                            "message" => $result['return_msg'],
                        ];
                    }

                    return json_encode($data);
                }

                //京东收银-微信
                if ($ways && $ways->ways_type == 6002) {
                    $data_public = [
                        'pay_type' => 'WX',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $store->user_id,
                    ];

                    return $this->jd_pay_public($data_insert, $data_public);
                }

                //联拓富收银-微信
                if ($ways && $ways->ways_type == 10002) {
                    $data_public = [
                        'pay_type' => 'WX',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $store->user_id,
                    ];

                    return $this->ltf_pay_public($data_insert, $data_public);
                }

                //快钱微信支付扫一扫
                if ($ways && $ways->ways_type == 3002) {
                    $data_public = [
                        'pay_type' => 'weixin',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];
                    return $this->mybank_pay_public($data_insert, $data_public);
                }

                //和融通-微信
                if ($ways && $ways->ways_type == 9002) {
                    $data_public = [
                        'pay_type' => 'wx',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $store->user_id,
                    ];

                    return $this->h_pay_public($data_insert, $data_public);
                }

                //新大陆微信
                if ($ways && $ways->ways_type == 8002) {
                    //
                    $config = new NewLandConfigController();
                    $new_land_config = $config->new_land_config($config_id);
                    if (!$new_land_config) {
                        return json_encode([
                            'status' => 2,
                            'message' => '新大陆配置不存在请检查配置'
                        ]);
                    }

                    $mybank_merchant = $config->new_land_merchant($store_id, $store_pid);
                    if (!$mybank_merchant) {
                        return json_encode([
                            'status' => 2,
                            'message' => '商户新大陆通道未开通'
                        ]);
                    }
                    $request_data = [
                        'out_trade_no' => $out_trade_no,
                        'code' => $code,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'key' => $mybank_merchant->nl_key,
                        'org_no' => $new_land_config->org_no,
                        'merc_id' => $mybank_merchant->nl_mercId,
                        'trm_no' => $mybank_merchant->trmNo,
                        'op_sys' => '3',
                        'opr_id' => $merchant_id,
                        'trm_typ' => 'T',
                        'payChannel' => 'WXPAY',
                    ];

                    //入库参数
                    $data_insert['out_trade_no'] = $out_trade_no;
                    $data_insert['ways_type'] = $ways->ways_type;
                    $data_insert['company'] = $ways->company;
                    $data_insert['ways_type_desc'] = '微信支付';
                    $data_insert['ways_source'] = $ways->ways_source;
                    $data_insert['ways_source_desc'] = '微信支付';


                    return $this->newland_pay_public($data_insert, $request_data);
                }

                //随行付-微信
                if ($ways && $ways->ways_type == 13002) {
                    $data_public = [
                        'pay_type' => 'WECHAT',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->vbill_pay_public($data_insert, $data_public);
                }

                //随行付a-微信
                if ($ways && $ways->ways_type == 19002) {
                    $data_public = [
                        'pay_type' => 'WECHAT',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->vbilla_pay_public($data_insert, $data_public);
                }

                //哆啦宝-微信
                if ($ways && $ways->ways_type == 15002) {
                    $data_public = [
                        'pay_type' => 'WECHAT',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->dlb_pay_public($data_insert, $data_public);
                }

                //传化微信
                if ($ways && $ways->ways_type == 12002) {
                    $data_public = [
                        'channel' => 'WECHAT_POS',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->tf_pay_public($data_insert, $data_public);
                }

                //汇付-微信
                if ($ways && $ways->ways_type == 18002) {
                    $data_public = [
                        'pay_type' => 'WECHAT',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->huipay_pay_public($data_insert, $data_public);
                }

                //工行微信
                if ($ways && $ways->ways_type == 20002) {
                    $data_public = [
                        'payment' => '1',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id
                    ];

                    return $this->lianfu_pay_public($data_insert, $data_public);
                }

                //农商行微信
                if ($ways && $ways->ways_type == 20801) {
                    $data_public = [
                        'payment' => '1',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id
                    ];

                    return $this->nongjin_pay_public($data_insert, $data_public);
                }
                
                //扫呗微信
                if ($ways && $ways->ways_type == 30080) {
                    $data_public = [
                        'payment' => '1',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id
                    ];

                    return $this->saobei_pay_public($data_insert, $data_public);
                }
                
                //平安银行微信
                if ($ways && $ways->ways_type == 30011) {
                    $data_public = [
                        'payment' => '1',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id
                    ];
                    return $this->pingan_pay_public($data_insert, $data_public);
                }
                
                //平安银行微信
                if ($ways && $ways->ways_type == 37001) {
                    $data_public = [
                        'payment' => '1',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id
                    ];
                    return $this->jiujiang_pay_public($data_insert, $data_public);
                }
                
                //邮储银行微信
                if ($ways && $ways->ways_type == 26002) {
                    $data_public = [
                        'payment' => '1',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id
                    ];
                    return $this->you_pay_public($data_insert, $data_public);
                }

                //海科融通 微信 被扫
                if ($ways && $ways->ways_type == 22002) {
                    $data_public = [
                        'pay_type' => 'WECHAT',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];
                    return $this->hkrt_pay_public($data_insert, $data_public);
                }

                //易生支付 微信 被扫
                if ($ways && $ways->ways_type == 21002) {
                    $data_public = [
                        'pay_type' => 'WECHAT',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                        "settlement_type"=>$ways->settlement_type ?? ''
                    ];

                    return $this->easypay_pay_public($data_insert, $data_public);
                }

                //联动优势 微信 被扫
                if ($ways && $ways->ways_type == 5002) {
                    $data_public = [
                        'orderType' => 'wechat',
                        'goodsId' => time(),
                        'pay_type' => 'WECHAT',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id
                    ];

                    return $this->linkage_pay_public($data_insert, $data_public);
                }

                //威富通 微收银 微信 被扫
                if ($ways && $ways->ways_type == 27002) {
                    $data_public = [
                        'pay_type' => 'WECHAT',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->wft_pay_public($data_insert, $data_public);
                }
                
                //威富通 微收银 微信 被扫
                if ($ways && $ways->ways_type == 30050) {
                    $data_public = [
                        'pay_type' => 'WECHAT',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->wing_pay_public($data_insert, $data_public);
                }


                //国通星驿支付-微信


                //汇旺财 微收银 微信 被扫
                if ($ways && $ways->ways_type == 28002) {
                    $data_public = [
                        'pay_type' => 'WECHAT',
                        'return_params' => '原样返回',
                        'title' => '微信收款',
                        'ways_source_desc' => '微信支付',
                        'ways_type_desc' => '微信支付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->hwc_pay_public($data_insert, $data_public);
                }

            }

            //银联渠道
            if ($str == "62") {
                $out_trade_no = date('YmdHis', time()) . substr(microtime(), 2, 6) . sprintf('%03d', rand(0, 999));
                $obj_ways = new PayWaysController(['total_amount' => $total_amount]);
                $ways = $obj_ways->ways_source('unionpay', $store_id, $store_pid);
                /**2024-08-27 屏蔽
                $data_insert ['rate'] = $ways->rate;
                $data_insert['fee_amount'] = $ways->rate * $total_amount / 100;
                 **/



                //验证扣费模式
                list($isRun,$error)=\App\Services\Store\StoreSignService::validateSign((string)$ways->store_id,(string)$ways->company);
                if($isRun==false){
                    return json_encode([
                        'status' => 2,
                        'message' => $error
                    ]);
                }


                /**
                 * 2024-08-27 新增
                 */
                //在这里使用新的费率
                //费率调整：
                $service = new PayService();
                $user_rate_obj = $obj_ways->getCostRate($ways->ways_type, $tg_user_id);
                $cost_rate=$service->getYSFCostRate($user_rate_obj,$total_amount);
                //扫码费率入库
                if ($cost_rate) $data_insert['cost_rate'] = $cost_rate;
                $waysRate=$service->getYSFWayRate($ways,$total_amount);
                $data_insert['rate'] = $waysRate;
                $data_insert['fee_amount'] = $waysRate * $total_amount / 100;

                //工行支付宝
                if ($ways && $ways->ways_type == 20803) {
                    $data_public = [
                        'payment' => '2',
                        'goodsId' => time(),
                        'title' => '云闪付收款',
                        'ways_source_desc' => '云闪付',
                        'ways_type_desc' => '云闪付',
                        'code' => $code,
                        'out_trade_no' => $out_trade_no,
                        'other_no' => $out_trade_no,
                        'config_id' => $config_id,
                        'store_id' => $store_id,
                        'store_pid' => $store_pid,
                        'ways_type' => '' . $ways->ways_type . '',
                        'ways_source' => $ways->ways_source,
                        'company' => $ways->company,
                        'total_amount' => $total_amount,
                        'remark' => $remark,
                        'device_id' => $device_id,
                        'shop_name' => $shop_name,
                        'merchant_id' => $merchant_id,
                        'store_name' => $store_name,
                        'tg_user_id' => $tg_user_id,
                    ];

                    return $this->nongjin_pay_public($data_insert, $data_public);
                }
            }
            return json_encode([
                'status' => 2,
                'message' => '暂不支持此二维码'
            ]);
        } catch (\Exception $exception) {
            Log::info('微收银扫码-返回报错');
            Log::info($exception->getMessage().' | '.$exception->getFile().' | '.$exception->getLine());
            return json_encode([
                'status' => '-1',
                'message' => $exception->getMessage().' | '.$exception->getFile().' | '.$exception->getLine()
            ]);
        }
    }
    
    //扫呗
    public function saobei_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $tg_user_id = $data['tg_user_id'];
        $code = $data['code'];

        $config = new SaobeiConfigController();
        $h_merchant = $config->saobei_merchant($store_id, $store_pid);
        if (!$h_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '扫呗商户号不存在'
            ]);
        }

        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\lianfu\PayController();
        $data1['pay_ver'] = '100';//版本号
        $data1['pay_type'] = '000';//支付方式
        $data1['service_id'] = '010';//接口类型
        $data1['merchant_no'] = $h_merchant->merchantNo;//商户号
        $data1['terminal_id'] = $h_merchant->zhongduan;//终端号
        $data1['terminal_trace'] = $out_trade_no;//终端流水号
        $data1['terminal_time'] = date('Ymdhis', time());//终端交易时间
        $data1['auth_no'] = $code;//付款码
        $data1['total_fee'] = intval($total_amount*100);//付款金额
        $return = $obj->scan_pay3($data1,$h_merchant->access_token);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['out_trade_no'];
            $user_info ='';
            $pay_time = date('Y-m-d H:i:s', time());
            $buyer_pay_amount = $total_amount;
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

            $data_update=  [
                'trade_no' => $trade_no,
                'buyer_id' => $user_info,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '20000', //返佣来源
                'source_desc' => 'lianfu', //返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'ways_source' => $data['ways_source'],
                    'out_transaction_id' => $trade_no
                ]
            ]);
        }

        //正在支付
        if ($return['status'] == 2) {
            $trade_no = $return['data']['out_trade_no'];
            $data_update=  [
                'trade_no' => $trade_no,
            ];
            $this->update_day_order($data_update, $out_trade_no);
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

    }


    //京东收银支付宝微信等扫一扫公共部分
    public function jd_pay_public($data_insert, $data)
    {
        try {
            //读取配置
            $store_id = $data['store_id'];
            $store_pid = $data['store_pid'];
            $merchant_id = $data['merchant_id'];
            $total_amount = $data['total_amount'];
            $ways_type = $data['ways_type'];
            $store_name = $data['store_name'];
            $config_id = $data['config_id'];
            $desc = $data['ways_type_desc'];
            $title = $data['title'];
            $tg_user_id = $data['tg_user_id'];//推广员ID;
            $config = new JdConfigController();
            $jd_config = $config->jd_config($data['config_id']);
            if (!$jd_config) {
                return json_encode([
                    'status' => 2,
                    'message' => '京东配置不存在请检查配置'
                ]);
            }

            $jd_merchant = $config->jd_merchant($store_id, $store_pid);
            if (!$jd_merchant) {
                return json_encode([
                    'status' => 2,
                    'message' => '京东商户号不存在'
                ]);
            }

            $out_trade_no = $data['out_trade_no'];

            //入库参数
            $data_insert['out_trade_no'] = $out_trade_no;
            $data_insert['ways_type'] = $data['ways_type'];
            $data_insert['company'] = $data['company'];
            $data_insert['ways_type_desc'] = $data['ways_type_desc'];
            $data_insert['ways_source'] = $data['ways_source'];
            $data_insert['ways_source_desc'] = $data['ways_source_desc'];

            $insert_re = $this->insert_day_order($data_insert);

            if (!$insert_re) {
                return json_encode([
                    'status' => 2,
                    'message' => '订单未入库'
                ]);
            }

            $obj = new \App\Api\Controllers\Jd\PayController();
            $data['notify_url'] = url('/api/jd/pay_notify_url');//回调地址
            $data['request_url'] = $obj->scan_url;//请求地址;
            $data['merchant_no'] = $jd_merchant->merchant_no;
            $data['md_key'] = $jd_merchant->md_key;//
            $data['des_key'] = $jd_merchant->des_key;//
            $data['systemId'] = $jd_config->systemId;//

            $return = $obj->scan_pay($data);

            if ($return['status'] == 0) {
                return json_encode([
                    'status' => 2,
                    'message' => $return['message']
                ]);
            }


            //返回支付成功
            if ($return['status'] == 1) {
                $trade_no = $return['data']['tradeNo'];
                $channelNoSeq = isset($return['data']['channelNoSeq']) ? $return['data']['channelNoSeq'] : $out_trade_no;//条码
                $buyer_pay_amount = $return['data']['piAmount'] / 100;
                $pay_time = date('Y-m-d H:i:s', strtotime($return['data']['payFinishTime']));
                $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

                $data_update = [
                    'trade_no' => $channelNoSeq,
                    'buyer_id' => '',
                    'buyer_logon_id' => '',
                    'status' => '1',
                    'pay_status_desc' => '支付成功',
                    'pay_status' => 1,
                    'payment_method' => '',
                    'pay_time' => $pay_time,
                    'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
                ];
                $this->update_day_order($data_update, $out_trade_no);

                //支付成功后的动作
                $data = [
                    'ways_type' => $data['ways_type'],
                    'company' => $data_insert['company'],
                    'ways_type_desc' => $data['ways_type_desc'],
                    'source_type' => '6000',//返佣来源
                    'source_desc' => '京东金融',//返佣来源说明
                    'total_amount' => $total_amount,
                    'out_trade_no' => $out_trade_no,
                    'rate' => $data_insert['rate'],
                    'fee_amount' => $data_insert['fee_amount'],
                    'merchant_id' => $merchant_id,
                    'store_id' => $store_id,
                    'user_id' => $tg_user_id,
                    'config_id' => $config_id,
                    'store_name' => $store_name,
                    'ways_source' => $data['ways_source'],
                    'pay_time' => $pay_time,
                    'no_push' => '1',//不推送
                    'no_fuwu' => '1',//不服务消息
                    'no_print' => '1',//不打印
                    //'no_v' => '1',//不小盒子播报

                ];


                PaySuccessAction::action($data);


                return json_encode([
                    'status' => 1,
                    'pay_status' => '1',
                    'message' => '支付成功',
                    'data' => [
                        'out_trade_no' => $out_trade_no,
                        'ways_type' => $ways_type,
                        'total_amount' => $total_amount,
                        'store_id' => $store_id,
                        'store_name' => $store_name,
                        'config_id' => $config_id,
                        'pay_time' => $pay_time,
                        'trade_no' => $trade_no,
                        'out_transaction_id' => $channelNoSeq,
                    ]
                ]);

            }

            //正在支付
            if ($return['status'] == 2) {
                return json_encode([
                    'status' => 9,//正在支付 app 和微收银 状态不一样
                    'pay_status' => '2',
                    'message' => '正在支付',
                    'data' => [
                        'out_trade_no' => $out_trade_no,
                        'ways_type' => $ways_type,
                        'total_amount' => $total_amount,
                        'store_id' => $store_id,
                        'store_name' => $store_name,
                        'config_id' => $config_id,
                    ]
                ]);
            }

            //支付失败
            if ($return['status'] == 3) {
                return json_encode([
                    'status' => 2,
                    'pay_status' => '3',
                    'message' => $return['message'],
                    'data' => [
                        'out_trade_no' => $out_trade_no,
                        'ways_type' => $ways_type,
                        'total_amount' => $total_amount,
                        'store_id' => $store_id,
                        'store_name' => $store_name,
                        'config_id' => $config_id,
                    ]
                ]);
            }

        } catch
        (\Exception $exception) {
            Log::info($exception);
            return json_encode([
                'status' => 2,
                'message' => $exception->getMessage()
            ]);
        }
    }


    //快钱收银支付宝微信等扫一扫公共部分
    public function mybank_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];
        $remark = $data['remark'];
        $code = $data['code'];
        $type_source = $data['pay_type'];
        $config = new MyBankConfigController();


        $mybank_merchant = $config->mybank_merchant($store_id, $store_pid);
        if (!$mybank_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '快钱不存在'
            ]);
        }
        $wx_AppId = $mybank_merchant->wx_AppId;
        $MyBankConfig = $config->MyBankConfig($data['config_id'], $wx_AppId);
        if (!$MyBankConfig) {
            return json_encode([
                'status' => 2,
                'message' => '快钱配置不存在请检查配置'
            ]);
        }
        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);

        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }


        $data['type_source'] = $type_source;//alipay,weixin
        $data['out_trade_no'] = $out_trade_no;
        $data['mybank_merchant_id'] = $mybank_merchant->MerchantId;
        $data['merchant_id'] = $merchant_id;
        $data['code'] = $code;
        $data['TotalAmount'] = $total_amount * 100;//单位分
        $data['is_fq'] = 0;//0
        $data['fq_num'] = 3;//3
        $data['hb_fq_seller_percent'] = 0;//0
        $data['buydata'] = [];//数组
        $data['SettleType'] = 'T1';//T1
        $data['remark'] = $remark;
        $data['body'] = $title;
        $data['store_id'] = $store_id;
        $data['attach'] = $remark;//附加信息，原样返回。
        $data['PayLimit'] = "";//禁用方式
        $data['config_id'] = $config_id;


        $obj = new TradePayController();
        $return = $obj->TradePay($data);


        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['MerchantOrderNo'];//条码订单
            $pay_time = date('Y-m-d H:i:s', strtotime($return['data']['GmtPayment']));
            $payment_method = strtolower($return['data']['Credit']);
            $buyer_id = '';
            //微信付款的id
            if ($data['type_source'] == 'weixin') {
                $buyer_id = $return['data']['SubOpenId'];
            }
            if ($data['type_source'] == 'alipay') {
                $buyer_id = $return['data']['BuyerUserId'];
            }


            $data_update = [
                'trade_no' => $trade_no,
                'buyer_id' => $buyer_id,
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => $payment_method,
                'pay_time' => $pay_time,
            ];

            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'company' => $data_insert['company'],
                'ways_type_desc' => $data['ways_type_desc'],
                'source_type' => '3000',//返佣来源
                'source_desc' => '快钱支付',//返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'no_push' => '1',//不推送
                'no_fuwu' => '1',//不服务消息
                'no_print' => '1',//不打印
                //'no_v' => '1',//不小盒子播报


            ];


            PaySuccessAction::action($data);

            $out_transaction_id = $out_trade_no;
            if ($type_source == "weixin") {
                $out_transaction_id = $trade_no;
            }

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'out_transaction_id' => $out_transaction_id,

                ]
            ]);

        }

        //正在支付
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }


    }


    //和融通
    public function h_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];

        $config = new HConfigController();
        $h_config = $config->h_config($data['config_id']);

        if (!$h_config) {
            return json_encode([
                'status' => 2,
                'message' => '和融通配置不存在请检查配置'
            ]);
        }

        $h_merchant = $config->h_merchant($store_id, $store_pid);
        if (!$h_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '和融通商户号不存在'
            ]);
        }

        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);

        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\Huiyuanbao\PayController();
        $data['notify_url'] = url('/api/huiyuanbao/pay_notify');//回调地址
        $data['request_url'] = $obj->scan_url;//请求地址;
        $data['mid'] = $h_merchant->h_mid;
        $data['md_key'] = $h_config->md_key;//
        $data['orgNo'] = $h_config->orgNo;//
        $return = $obj->scan_pay($data);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }


        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = '112121' . $return['data']['transactionId'];
            $pay_time = date('Y-m-d H:i:s', time());
            $buyer_pay_amount = $total_amount;
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

            $data_update = [
                'trade_no' => $trade_no,
                'buyer_id' => '',
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);


            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'company' => $data_insert['company'],
                'ways_type_desc' => $data['ways_type_desc'],
                'source_type' => '9000',//返佣来源
                'source_desc' => '和融通',//返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'no_push' => '1',//不推送
                'no_fuwu' => '1',//不服务消息
                'no_print' => '1',//不打印
                //'no_v' => '1',//不小盒子播报

            ];


            PaySuccessAction::action($data);


            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'out_transaction_id' => $trade_no,
                ]
            ]);

        }

        //正在支付
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }


    }


    //新大陆
    public function newland_pay_public($data_insert, $data_request)
    {
        try {
            $insert_re = $this->insert_day_order($data_insert);

            if (!$insert_re) {
                return json_encode([
                    'status' => 2,
                    'message' => '订单未入库'
                ]);
            }

            $obj = new \App\Api\Controllers\Newland\PayController();
            $return = $obj->scan_pay($data_request);

            if ($return['status'] == 0) {
                return json_encode([
                    'status' => 2,
                    'message' => $return['message']
                ]);
            }


            //返回支付成功
            if ($return['status'] == 1) {
                $trade_no = $return['data']['orderNo'];
                $pay_time = date('Y-m-d H:i:s', strtotime($return['data']['sysTime']));
                $payment_method = '';
                $buyer_id = '';

                $data_update = [
                    'trade_no' => $trade_no,
                    'buyer_id' => $buyer_id,
                    'status' => '1',
                    'pay_status_desc' => '支付成功',
                    'pay_status' => 1,
                    'payment_method' => $payment_method,
                    'pay_time' => $pay_time,
                ];
                $this->update_day_order($data_update, $data_insert['out_trade_no']);

                //支付成功后的动作
                $data = [
                    'ways_type' => $data_insert['ways_type'],
                    'company' => $data_insert['company'],
                    'ways_type_desc' => $data_insert['ways_type_desc'],
                    'source_type' => '8000',//返佣来源
                    'source_desc' => '新大陆',//返佣来源说明
                    'total_amount' => $data_insert['total_amount'],
                    'out_trade_no' => $data_insert['out_trade_no'],
                    'rate' => $data_insert['rate'],
                    'fee_amount' => $data_insert['fee_amount'],
                    'merchant_id' => $data_insert['merchant_id'],
                    'store_id' => $data_insert['store_id'],
                    'user_id' => $data_insert['user_id'],
                    'config_id' => $data_insert['config_id'],
                    'store_name' => $data_insert['store_name'],
                    'ways_source' => $data_insert['ways_source'],
                    'pay_time' => $pay_time,
                    'no_push' => '1',//不推送
                    'no_fuwu' => '1',//不服务消息
                    'no_print' => '1',//不打印
                    //'no_v' => '1',//不小盒子播报

                ];


                PaySuccessAction::action($data);


                return json_encode([
                    'status' => 1,
                    'pay_status' => '1',
                    'message' => '支付成功',
                    'data' => [
                        'out_trade_no' => $data_insert['out_trade_no'],
                        'ways_type' => $data_insert['ways_type'],
                        'total_amount' => $data_insert['total_amount'],
                        'store_id' => $data_insert['store_id'],
                        'store_name' => $data_insert['store_name'],
                        'config_id' => $data_insert['config_id'],
                        'pay_time' => $pay_time,
                        'trade_no' => $trade_no,
                        'out_transaction_id' => $trade_no,
                    ]
                ]);

            }


            //正在支付
            if ($return['status'] == 2) {
                return json_encode([
                    'status' => 9,
                    'pay_status' => '2',
                    'message' => '正在支付',
                    'data' => [
                        'out_trade_no' => $data_insert['out_trade_no'],
                        'ways_type' => $data_insert['ways_type'],
                        'total_amount' => $data_insert['total_amount'],
                        'store_id' => $data_insert['store_id'],
                        'store_name' => $data_insert['store_name'],
                        'config_id' => $data_insert['config_id'],
                        'ways_source' => $data_insert['ways_source'],
                    ]
                ]);
            }


            //支付失败
            if ($return['status'] == 3) {
                return json_encode([
                    'status' => 2,
                    'pay_status' => '3',
                    'message' => '支付失败',
                    'data' => [
                        'out_trade_no' => $data_insert['out_trade_no'],
                        'ways_type' => $data_insert['ways_type'],
                        'total_amount' => $data_insert['total_amount'],
                        'store_id' => $data_insert['store_id'],
                        'store_name' => $data_insert['store_name'],
                        'config_id' => $data_insert['config_id'],
                    ]
                ]);
            }


        } catch (\Exception $exception) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => $exception->getMessage()
            ]);
        }

    }


    //联拓富收银支付宝微信等扫一扫公共部分
    public function ltf_pay_public($data_insert, $data)
    {

        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];
        $config = new LtfConfigController();

        $ltf_merchant = $config->ltf_merchant($store_id, $store_pid);
        if (!$ltf_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '商户号不存在'
            ]);
        }

        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);

        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\Ltf\PayController();
        $data['notify_url'] = url('/api/ltf/pay_notify_url');//回调地址
        $data['request_url'] = $obj->scan_url;//请求地址;
        $data['merchant_no'] = $ltf_merchant->merchantCode;
        $data['appId'] = $ltf_merchant->appId;//
        $data['key'] = $ltf_merchant->md_key;//


        $return = $obj->scan_pay($data);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }


        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['outTransactionId'];
            $buyer_id = $return['data']['buyerId'];
            $pay_time = date('Y-m-d H:i:s', strtotime($return['data']['payTime']));
            $buyer_pay_amount = $return['data']['receiptAmount'];
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

            $data_update = [
                'trade_no' => $trade_no,
                'buyer_id' => $buyer_id,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];

            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '10000',//返佣来源
                'source_desc' => '联拓富',//返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,

            ];


            PaySuccessAction::action($data);


            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'ways_source' => $data['ways_source'],
                    'out_transaction_id' => $trade_no,


                ]
            ]);

        }

        //正在支付
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,

                ]
            ]);
        }


    }


    //随行付收银支付宝微信等扫一扫公共部分
    public function vbill_pay_public($data_insert, $data)
    {

        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];
        $config = new VbillConfigController();
        $vbill_config = $config->vbill_config($data['config_id']);
        if (!$vbill_config) {
            return json_encode([
                'status' => 2,
                'message' => '随行付配置不存在请检查配置'
            ]);
        }

        $vbill_merchant = $config->vbill_merchant($store_id, $store_pid);
        if (!$vbill_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '随行付商户号不存在'
            ]);
        }

        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);

        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\Vbill\PayController();
        $data['notify_url'] = url('/api/vbill/pay_notify_url');//回调地址
        $data['request_url'] = $obj->scan_url;//请求地址;
        $data['mno'] = $vbill_merchant->mno;
        $data['privateKey'] = $vbill_config->privateKey;//
        $data['sxfpublic'] = $vbill_config->sxfpublic;//
        $data['orgId'] = $vbill_config->orgId;//

        $return = $obj->scan_pay($data);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }
        // file_put_contents('0803.txt', json_encode($return) . "\r\n", FILE_APPEND);

        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['respData']['sxfUuid'];
            $pay_time = date('Y-m-d H:i:s', strtotime($return['data']['respData']['payTime']));
            $buyer_pay_amount = $return['data']['respData']['totalOffstAmt'];
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');
            // $buyer_id = $return['data']['respData']['buyerId'];
            $buyer_id = '';

            $data_update= [
                'trade_no' => $trade_no,
                'buyer_id' => $buyer_id,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);


            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '13000',//返佣来源
                'source_desc' => '随行付',//返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",


            ];


            PaySuccessAction::action($data);


            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'out_transaction_id' => $trade_no,
                    'ways_source' => $data['ways_source'],

                ]
            ]);

        }

        //正在支付
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $data['ways_source'],

                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $data['ways_source'],

                ]
            ]);
        }


    }


    //随行付a收银支付宝微信等扫一扫公共部分
    public function vbilla_pay_public($data_insert, $data)
    {

        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];
        $config = new VbillConfigController();
        $vbill_config = $config->vbilla_config($data['config_id']);
        if (!$vbill_config) {
            return json_encode([
                'status' => 2,
                'message' => '随行付配置不存在请检查配置'
            ]);
        }

        $vbill_merchant = $config->vbilla_merchant($store_id, $store_pid);
        if (!$vbill_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '随行付商户号不存在'
            ]);
        }

        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);

        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\Vbill\PayController();
        $data['notify_url'] = url('/api/vbill/pay_notify_a_url');//回调地址
        $data['request_url'] = $obj->scan_url;//请求地址;
        $data['mno'] = $vbill_merchant->mno;
        $data['privateKey'] = $vbill_config->privateKey;//
        $data['sxfpublic'] = $vbill_config->sxfpublic;//
        $data['orgId'] = $vbill_config->orgId;//

//        Log::info('微收银-随行付-被扫');
//        Log::info($data);
        $return = $obj->scan_pay($data);
//        Log::info($return);

        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['respData']['sxfUuid'];
            $pay_time = date('Y-m-d H:i:s', strtotime($return['data']['respData']['payTime']));
            $buyer_pay_amount = $return['data']['respData']['totalOffstAmt'];
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');
            $buyer_id = $return['data']['respData']['buyerId'];

            $data_update= [
                'trade_no' => $trade_no,
                'buyer_id' => $buyer_id,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);


            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '19000',//返佣来源
                'source_desc' => '随行付A',//返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",


            ];


            PaySuccessAction::action($data);


            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'out_transaction_id' => $trade_no,
                    'ways_source' => $data['ways_source'],

                ]
            ]);

        }

        //正在支付
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $data['ways_source'],

                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $data['ways_source'],

                ]
            ]);
        }

    }


    //哆啦宝
    public function dlb_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];
        $manager = new ManageController();
        $dlb_config = $manager->pay_config($data['config_id']);

        if (!$dlb_config) {
            return json_encode([
                'status' => 2,
                'message' => '哆啦宝配置配置不存在请检查配置'
            ]);
        }

        $dlb_merchant = $manager->dlb_merchant($store_id, $store_pid);
        if (!$dlb_merchant && !empty($dlb_merchant->mch_num) && !empty($dlb_merchant->shop_num) && !empty($dlb_merchant->machine_num)) {
            return json_encode([
                'status' => 2,
                'message' => '哆啦宝配置商户未补充商户编号等信息!'
            ]);
        }
        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);

        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }
        $request = [
            "accessKey" => $dlb_config->access_key,
            "secretKey" => $dlb_config->secret_key,
            "agentNum" => $dlb_config->agent_num,
            "customerNum" => $dlb_merchant->mch_num,
            "authCode" => $data['code'],
            "machineNum" => $dlb_merchant->machine_num,
            "shopNum" => $dlb_merchant->shop_num,
            "requestNum" => $out_trade_no,
            "amount" => $total_amount,
            "source" => 'API',
            //"payType" => "NATIVE",
            'callbackUrl' => url('api/dlb/pay_notify')

        ];
        $return = $manager->pay_scan($request);

        if ($return['status'] == 1) {
            $scanpay_data = $return['data'];
            //下单成功
            $timewait = !empty($dlb_config) && $dlb_config->qwx_timewait > 0 && $dlb_config->qwx_timewait < 10 ? $dlb_config->qwx_timewait : 3;
            sleep($timewait);
            $query_data = [
                "accessKey" => $dlb_config->access_key,
                "secretKey" => $dlb_config->secret_key,
                "agentNum" => $dlb_config->agent_num,
                "customerNum" => $dlb_merchant->mch_num,
                "shopNum" => $dlb_merchant->shop_num,
                "requestNum" => $out_trade_no
            ];
            $return = $manager->query_bill($query_data);

            if ($return['status'] == 1) {
                $query_result = $return['data'];
                if ($query_result['status'] == "SUCCESS") {
                    $pay_time = $query_result['completeTime'];
                    $trade_no = $query_result['orderNum'];
                    $buyer_pay_amount = $query_result['orderAmount'];

                    $data_update=   [
                        'trade_no' => $trade_no,
                        'buyer_id' => '',
                        'buyer_logon_id' => '',
                        'status' => '1',
                        'pay_status_desc' => '支付成功',
                        'pay_status' => 1,
                        'payment_method' => '',
                        'pay_time' => $pay_time,
                        'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
                    ];
                    $this->update_day_order($data_update, $out_trade_no);


                    //支付成功后的动作
                    $data = [
                        'ways_type' => $data['ways_type'],
                        'ways_type_desc' => $data['ways_type_desc'],
                        'source_type' => '15000',//返佣来源
                        'source_desc' => '哆啦宝',//返佣来源说明
                        'company' => 'dlb',
                        'fee_amount' => $data_insert['fee_amount'],
                        'total_amount' => $total_amount,
                        'out_trade_no' => $out_trade_no,
                        'rate' => $data_insert['rate'],
                        'merchant_id' => $merchant_id,
                        'store_id' => $store_id,
                        'user_id' => $tg_user_id,
                        'config_id' => $config_id,
                        'store_name' => $store_name,
                        'ways_source' => $data['ways_source'],
                        'pay_time' => $pay_time,
                        'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
                    ];


                    PaySuccessAction::action($data);

                    $return = [
                        'status' => 1,
                        'pay_status' => '1',
                        'message' => '支付成功',
                        'data' => [
                            'out_trade_no' => $out_trade_no,
                            'ways_type' => $ways_type,
                            'total_amount' => $total_amount,
                            'store_id' => $store_id,
                            'store_name' => $store_name,
                            'config_id' => $config_id,
                            'pay_time' => $pay_time,
                            'trade_no' => $trade_no,
                            'out_transaction_id' => $trade_no,
                            'ways_source' => $data['ways_source'],

                        ]
                    ];

                } elseif ($query_result['status'] == "INIT") {
                    $return = [
                        'status' => 9,
                        'pay_status' => '2',
                        'message' => '正在支付',
                        'data' => [
                            'out_trade_no' => $out_trade_no,
                            'ways_type' => $ways_type,
                            'total_amount' => $total_amount,
                            'store_id' => $store_id,
                            'store_name' => $store_name,
                            'config_id' => $config_id,
                        ]
                    ];
                } elseif ($query_result['status'] == "CANCEL") {
                    $return = [
                        'status' => 2,
                        'pay_status' => '3',
                        'message' => '支付失败',
                        'data' => [
                            'out_trade_no' => $out_trade_no,
                            'ways_type' => $ways_type,
                            'total_amount' => $total_amount,
                            'store_id' => $store_id,
                            'store_name' => $store_name,
                            'config_id' => $config_id,
                        ]
                    ];
                }
            }
        }
        return json_encode($return);

    }


    //传化
    public function tf_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];
        $channel = $data['channel'];

        $config = new TfConfigController();


        $h_merchant = $config->tf_merchant($store_id, $store_pid);
        if (!$h_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '传化商户号不存在'
            ]);
        }
        $h_config = $config->tf_config($data['config_id'], $h_merchant->qd);

        if (!$h_config) {
            return json_encode([
                'status' => 2,
                'message' => '传化配置不存在请检查配置'
            ]);
        }
        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);

        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\Tfpay\PayController();
        $data['mch_id'] = $h_config->mch_id;//
        $data['pub_key'] = $h_config->pub_key;//
        $data['pri_key'] = $h_config->pri_key;//
        $data['sub_mch_id'] = $h_merchant->sub_mch_id;//
        $data['notify_url'] = url('/api/tfpay/notify_url');
        $return = $obj->scan_pay($data);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }


        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['channel_no'];
            $user_info = $return['data']['user_info'];
            $pay_time = date('Y-m-d H:i:s', time());
            $buyer_pay_amount = $total_amount;
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

            $data_update=  [
                'trade_no' => $trade_no,
                'buyer_id' => $user_info,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];

            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '12000',//返佣来源
                'source_desc' => 'TF',//返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",


            ];


            PaySuccessAction::action($data);


            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'ways_source' => $data['ways_source'],
                    'out_transaction_id' => $trade_no,
                ]
            ]);


        }

        //正在支付
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }


    }


    //汇付收银,支付宝微信 b_扫_c 公共部分
    public function huipay_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];
        $config = new HuiPayConfigController();
        $hui_pay_config = $config->hui_pay_config($data['config_id']);
        if (!$hui_pay_config) {
            return json_encode([
                'status' => 2,
                'message' => '汇付配置不存在请检查配置'
            ]);
        }

        $hui_pay_merchant = $config->hui_pay_merchant($store_id, $store_pid);
        if (!$hui_pay_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '汇付商户不存在'
            ]);
        }
        if (!$hui_pay_merchant->mer_id) {
            return json_encode([
                'status' => 2,
                'message' => '汇付商户号不存在'
            ]);
        }
        if (!$hui_pay_merchant->user_cust_id) {
            return json_encode([
                'status' => 2,
                'message' => '汇付用户客户号不存在'
            ]);
        }

        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);
//        $insert_re = self::insert_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\HuiPay\PayController();
        $data['notify_url'] = url('/api/huipay/pay_notify_url'); //回调地址
        $data['request_url'] = $obj->back_scan; //反扫请求地址
        $data['mer_cust_id'] = $hui_pay_config->mer_cust_id; //商户客户号
        $data['user_cust_id'] = $hui_pay_merchant->user_cust_id; //用户客户号
        $data['private_key'] = $hui_pay_config->private_key;
        $data['public_key'] = $hui_pay_config->public_key;
        $data['org_id'] = $hui_pay_config->org_id; //机构号,渠道来源
        $data['device_id'] = $hui_pay_merchant->device_id??$data['device_id']; //机具id
//        Log::info('汇付b_扫_c: '.str_replace("\\/", "/", json_encode($data, JSON_UNESCAPED_UNICODE)));
        $return = $obj->scan_pay($data);
//        Log::info('汇付b_扫_c接口返回: '.str_replace("\\/", "/", json_encode($return, JSON_UNESCAPED_UNICODE)));
        //{"status":1,"message":"成功","data":{"bank_code":"SUCCESS","bank_message":"交易成功","cust_id":"6666000001036124","device_id":"SMSM34358719666880610","extension":"","fee_amt":"0.00","mer_priv":"","order_id":"wxscan20200109153908824837706","out_trans_id":"4200000488202001097182035737","party_order_id":"MCS00000012001091539097mg9ygiwVx","pay_type":"W0","platform_seq_id":"84086417201823744","service_amt":"0.00","trans_amt":"0.01","trans_date":"20200109","trans_time":"153909"}}
        //验签失败
        if ($return['status'] === '0') {
            return json_encode([
                'status' => '0',
                'message' => $return['message']
            ]);
        }

        //返回支付成功
        if ($return['status'] == 1) {
            $trans_date = isset($return['data']['trans_date'])?date('Y-m-d', strtotime($return['data']['trans_date'])):'';
            $trans_time = isset($return['data']['trans_time'])?date('H:i:s', strtotime($return['data']['trans_time'])):'';
            $trade_no = $return['data']['party_order_id']??''; //渠道支付凭证
            $pay_time = $trans_date.' '.$trans_time;
            $buyer_pay_amount = $return['data']['trans_amt']??''; //交易金额
//            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');
//            $buyer_id = $return['cust_id']; //支付用户id
            $data_update=  [
                'trade_no' => $trade_no,
//                'buyer_id' => $buyer_id,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];

            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '18000', //返佣来源
                'source_desc' => '汇付', //返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
//                'other_no' => $data_insert['other_no'],
                'rate' => $data_insert['rate'],
                'fee_amount' => $return['data']['fee_amt']??$data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
            ];

            PaySuccessAction::action($data);

            $test345 = [
                'out_trade_no' => $out_trade_no,
                'ways_type' => $ways_type,
                'total_amount' => $total_amount,
                'store_id' => $store_id,
                'store_name' => $store_name,
                'config_id' => $config_id,
                'pay_time' => $pay_time,
                'trade_no' => $trade_no,
                'ways_source' => $data['ways_source']
            ];
//            Log::info('汇付反扫返回值：'.str_replace("\\/", "/", json_encode($test345, JSON_UNESCAPED_UNICODE)));
            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'ways_source' => $data['ways_source'],
                    'out_transaction_id' => $trade_no,
                ]
            ]);
        }

        //正在支付
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 1,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }
    }


    //工行
    public function lianfu_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $tg_user_id = $data['tg_user_id'];

        $config = new LianfuConfigController();
        $h_merchant = $config->lianfu_merchant($store_id, $store_pid);
        if (!$h_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '工行商户号不存在'
            ]);
        }

        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\lianfu\PayController();
        $data['apikey'] = $h_merchant->apikey;//商户号
        $data['signkey'] = $h_merchant->signkey;//msgid
        $data['appid'] = $h_merchant->appid;
        $return = $obj->scan_pay($data);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['order_id'];
            $user_info ='';
            $pay_time = date('Y-m-d H:i:s', time());
            $buyer_pay_amount = $total_amount;
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

            $data_update=  [
                'trade_no' => $trade_no,
                'buyer_id' => $user_info,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '20000', //返佣来源
                'source_desc' => 'lianfu', //返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'ways_source' => $data['ways_source'],
                    'out_transaction_id' => $trade_no
                ]
            ]);
        }

        //正在支付
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

    }

    //农商行
    public function nongjin_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $tg_user_id = $data['tg_user_id'];

        $config = new NongjinConfigController();
        $h_merchant = $config->nongjin_merchant($store_id, $store_pid);
        if (!$h_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '农商行商户号不存在'
            ]);
        }

        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\lianfu\PayController();
        $data['merchantNo'] = $h_merchant->merchantNo;//商户号
        $data['signkey'] = $h_merchant->signkey;//key
        $data['terminalNo'] = $h_merchant->terminalNo;//终端号
        $data['batchNo'] = $h_merchant->batchNo;//批次号
        $return = $obj->scan_pay1($data);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['itpOrderId'];
            $user_info ='';
            $pay_time = date('Y-m-d H:i:s', time());
            $buyer_pay_amount = $total_amount;
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

            $data_update=  [
                'trade_no' => $trade_no,
                'buyer_id' => $user_info,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '20000', //返佣来源
                'source_desc' => 'lianfu', //返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'ways_source' => $data['ways_source'],
                    'out_transaction_id' => $trade_no
                ]
            ]);
        }

        //正在支付
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

    }
    
    //平安银行
    public function pingan_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $tg_user_id = $data['tg_user_id'];
        $config = new PinganConfigController();
        $h_merchant = $config->pingan_merchant($store_id, $store_pid);
        if (!$h_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '平安银行商户号不存在'
            ]);
        }
        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }
        $obj = new \App\Api\Controllers\lianfu\PayController();
        if($data['ways_source']=='weixin'){
            $pingan_data['pay_way']='WXZF';
        }else if($data['ways_source']=='alipay'){
            $pingan_data['pay_way']='ZFBZF';
        }else if($data['ways_source']=='unionpay'){
            $pingan_data['pay_way']='YSF';
        }
        $pingan_data['out_order_id']=$out_trade_no;
        $pingan_data['enterpriseReg']=$h_merchant->enterpriseReg;
        $pingan_data['merchant_id']=$h_merchant->merchant_id;
        $pingan_data['sMchtIp']=$_SERVER['REMOTE_ADDR'];
        $pingan_data['sAuthCode']=$data['code'];
        $pingan_data['amount']=$total_amount;
        $pingan_data['date_time']=date('Y-m-d H:i:s',time());
        $pingan_data['push_url']=url('/api/wincode/pingan_pay');
        foreach (array_filter($pingan_data) as $k => $v){
            $Parameters[$k] = $v;
        }
        $buff = "";
        ksort($Parameters);
        foreach ($Parameters as $k => $v) {
            $buff .= $k . "=" . $v . "&";
        }
        $String = '';
        if (strlen($buff) > 0) {
            $String = substr($buff, 0, strlen($buff) - 1);
        }
        $String = $String . $h_merchant->appsecret;
        $re=hash('sha256', $String, true);
        $String = strtoupper(bin2hex($re));
        
        $json='{"appid":"'."$h_merchant->appid".'"'.',"timeStamp":"'.time().'000'.'"'.',"data":'.stripslashes(json_encode($pingan_data,JSON_UNESCAPED_SLASHES)).',"sign":"'.$String.'"'.'}';
        
        $return = $obj->scan_pay6($json);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['third_order_id'];
            $user_info ='';
            $pay_time = date('Y-m-d H:i:s', time());
            $buyer_pay_amount = $total_amount;
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

            $data_update=  [
                'trade_no' => $trade_no,
                'buyer_id' => $user_info,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '20000', //返佣来源
                'source_desc' => 'lianfu', //返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'ways_source' => $data['ways_source'],
                    'out_transaction_id' => $trade_no
                ]
            ]);
        }

        //正在支付
        if ($return['status'] == 2) {
            $trade_no = $return['data']['third_order_id'];
            $data_update=  [
                'trade_no' => $trade_no,
            ];
            $this->update_day_order($data_update, $out_trade_no);
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

    }
    
    //九江银行
    public function jiujiang_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $tg_user_id = $data['tg_user_id'];
        $config = new JiuJiangConfigController();

        $h_merchant = $config->jiujiang_merchant($store_id, $store_pid);
        if (!$h_merchant) {
            return json_encode([
                'status' => '2',
                'message' => '九江银行商户号不存在'
            ]);
        }
        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }
        $obj = new \App\Api\Controllers\JiuJiang\PayController();
        
        $postdate = array(
            'mchtNo' => $h_merchant->mchtNo, //商户号
            'termNo' => $h_merchant->termNo, // 终端号
            'private_key' => $h_merchant->private_key, // 私钥
            'out_trade_no' => $out_trade_no, // 商户订单号（被扫下单时，终端生成的订单号，终端流水唯一流水号）
            'total_amount' => $total_amount, 
            'authCode' => $data['code'],
        );
        $return = $obj->scan_pay($postdate);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['payNumber'];
            $user_info ='';
            $pay_time = date('Y-m-d H:i:s', time());
            $buyer_pay_amount = $total_amount;
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

            $data_update=  [
                'trade_no' => $trade_no,
                'buyer_id' => $user_info,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '20000', //返佣来源
                'source_desc' => 'lianfu', //返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'ways_source' => $data['ways_source'],
                    'out_transaction_id' => $trade_no
                ]
            ]);
        }

        //正在支付
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

    }
    
    
    //邮储银行
    public function you_pay_public($data_insert, $data)
    {
        //读取配置
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $tg_user_id = $data['tg_user_id'];
        $config = new LianfuyoupayConfigController();
        $h_merchant = $config->lianfu_merchant($store_id, $store_pid);
        if (!$h_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '商户号不存在'
            ]);
        }
        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }
         $obj = new \App\Api\Controllers\lianfuyouzheng\PayController();
        $data['apikey'] = $h_merchant->apikey; //
        $data['signkey'] = $h_merchant->signkey; //
        $data['pos_sn'] = $h_merchant->pos_sn; //
        $data['goods_name'] = '交易'; //
        $return = $obj->scan_pay($data);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //返回支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['orderNo'];
            $user_info ='';
            $pay_time = date('Y-m-d H:i:s', time());
            $buyer_pay_amount = $total_amount;
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

            $data_update=  [
                'trade_no' => $trade_no,
                'buyer_id' => $user_info,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount,//用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '20000', //返佣来源
                'source_desc' => 'lianfu', //返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'ways_source' => $data['ways_source'],
                    'out_transaction_id' => $trade_no
                ]
            ]);
        }

        //正在支付
        if ($return['status'] == 2) {
            $trade_no = $return['data']['third_order_id'];
            $data_update=  [
                'trade_no' => $trade_no,
            ];
            $this->update_day_order($data_update, $out_trade_no);
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                ]
            ]);
        }

    }
    
    


    //海科融通 被扫 公共
    public function hkrt_pay_public($data_insert, $data)
    {
        $ways_type_desc = $data['ways_type_desc'] ?? '';
        $ways_source_desc = $data['ways_source_desc'] ?? '';
        $code = $data['code'] ?? '';
        $out_trade_no = $data['out_trade_no'] ?? '';
        $config_id = $data['config_id'] ?? '';
        $store_id = $data['store_id'] ?? '';
        $store_pid = $data['store_pid'] ?? '';
        $ways_type = $data['ways_type'] ?? '';
        $ways_source = $data['ways_source'] ?? '';
        $company = $data['company'] ?? '';
        $total_amount = $data['total_amount'] ?? '';
        $remark = $data['remark'] ?? '';
        $device_id = $data['device_id'] ?? '';
        $shop_name = $data['shop_name'] ?? '';
        $merchant_id = $data['merchant_id'] ?? '';
        $store_name = $data['store_name'] ?? '';
        $tg_user_id = $data['tg_user_id'] ?? '';

        $config = new HkrtConfigController();
        $hkrt_config = $config->hkrt_config($config_id);
        if (!$hkrt_config) {
            return json_encode([
                'status' => 2,
                'message' => '海科融通配置不存在请检查配置'
            ]);
        }

        $hkrt_merchant = $config->hkrt_merchant($store_id, $store_pid);
        if (!$hkrt_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '海科融通商户号不存在'
            ]);
        }

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $ways_type;
        $data_insert['ways_type_desc'] = $ways_type_desc;
        $data_insert['company'] = $company;
        $data_insert['ways_source'] = $ways_source;
        $data_insert['ways_source_desc'] = $ways_source_desc;
        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\Hkrt\PayController();
        $hkrt_data = [
            'access_id' => $hkrt_config->access_id,
            'merch_no' => $hkrt_merchant->merch_no,
            'out_trade_no' => $out_trade_no,
            'total_amount' => $total_amount,
            'code' => $code,
            'notify_url' => url('/api/hkrt/pay_notify_url'), //回调地址
//            'sn' => '', //厂商终端号
//            'pn' => '', //SAAS终端号,标准服务商必填
            'remark' => $remark,
//            'limit_pay' => '0', //0-不限制贷记卡支付;1-禁止使用贷记卡支付。limit_pay默认为0
//            'receive_no' => '', //收账方(海科商户号)ledger_relation组内参数
//            'amt' => '', //分账金额（单位：元）
//            'goods_name' => '' //商品名称(仅限支付宝微信被扫，银联二维码上送字段也不会被使用)
            'access_key' => $hkrt_config->access_key
        ];
        Log::info('微收银-海科融通-被扫');
        Log::info($hkrt_data);
//        $hkrt_data['sign'] = $obj->getSignContent($hkrt_data, $hkrt_config->access_key);
//        Log::info($hkrt_data['sign']);
        $return = $obj->scan_pay($hkrt_data); //0-系统错误 1-成功 2-失败 3-交易进行中
        if ($return['status'] == '0') {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //返回支付成功
        if ($return['status'] == '1') {
            //            $return['data'] = '{
            //                "out_trade_no":"aliscan20200528103800950648811",
            //                "channel_trade_no":"011220052810381308990MC",
            //                "trade_no":"AL200528103801605753925627",
            //                "trade_status":1,
            //                "trade_type":"ALI",
            //                "trade_end_time":"2020-05-28 10:38:03",
            //                "userid":"2088012904744331",
            //                "trade_channel_end_time":"2020-05-28 10:38:02",
            //                "return_code":10000,
            //                "sign":"31E7A6AD0908910C0067F5402A4BFBE1"
            //            }';
            $pay_time = $return['data']['trade_end_time'] ?? '';
            $trade_no = $return['data']['trade_no'] ?? '';
            $other_no = $return['data']['channel_trade_no'] ?? '';
            $payment_method = $return['data']['trade_type'] ?? '';
            $data_update= [
                'trade_no' => $trade_no,
                'other_no' => $other_no,
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => $payment_method,
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $total_amount //用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $ways_type,
                'ways_type_desc' => $ways_type_desc,
                'company' => $company,
                'source_type' => '22000', //返佣来源
                'source_desc' => '海科融通', //返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $ways_source,
                'pay_time' => $pay_time,
                'device_id' => $device_id,
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'out_transaction_id' => $out_trade_no,
                    'ways_source' => $ways_source,
                ]
            ]);
        }

        //正在支付
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 9,
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $ways_source,
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $ways_source,
                ]
            ]);
        }

    }


    //易生支付 被扫 公共
    public function easypay_pay_public($data_insert, $data)
    {
        $ways_type_desc = $data['ways_type_desc'] ?? '';
        $ways_source_desc = $data['ways_source_desc'] ?? '';
        $code = $data['code'] ?? '';
        $out_trade_no = $data['out_trade_no'] ?? '';
        $config_id = $data['config_id'] ?? '';
        $store_id = $data['store_id'] ?? '';
        $store_pid = $data['store_pid'] ?? '';
        $ways_type = $data['ways_type'] ?? '';
        $ways_source = $data['ways_source'] ?? '';
        $company = $data['company'] ?? '';
        $total_amount = $data['total_amount'] ?? '';
        $remark = $data['remark'] ?? '';
        $device_id = $data['device_id'] ?? '';
        $shop_name = $data['shop_name'] ?? '';
        $merchant_id = $data['merchant_id'] ?? '';
        $store_name = $data['store_name'] ?? '';
        $tg_user_id = $data['tg_user_id'] ?? '';

        $config = new EasyPayConfigController();
        $easypay_config = $config->easypay_config($config_id);
        if (!$easypay_config) {
            return json_encode([
                'status' => '2',
                'message' => '易生支付配置不存在请检查配置'
            ]);
        }
        $version="easypay";
        if(in_array($ways_type,[61001,61002,61004])){
            $version="easypaya";
        }
        $easypay_merchant = $config->easypay_merchant($store_id, $store_pid,$version);
        if (!$easypay_merchant) {
            return json_encode([
                'status' => '2',
                'message' => '易生支付商户号不存在'
            ]);
        }

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $ways_type;
        $data_insert['ways_type_desc'] = $ways_type_desc;
        $data_insert['company'] = $company;
        $data_insert['ways_source'] = $ways_source;
        $data_insert['ways_source_desc'] = $ways_source_desc;
        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => '2',
                'message' => '订单未入库'
            ]);
        }

        $obj = new PayController();
        $easypay_data = [
            'channel_id' => $easypay_config->channel_id, //渠道编号
            'mno' => $easypay_merchant->termMercode, //终端商户编号
            'device_id' => $easypay_merchant->termTermcode, //终端编号
            'out_trade_no' => $out_trade_no, //商户订单号
            'total_amount' => $total_amount, //交易金额
            'code' => $code,
            "private_key"=>$easypay_config->private_key,
            "settlement_type"=>$data['settlement_type'] ?? '',
            'shop_name' => $shop_name //商品或支付单简要描述（给用户看）
        ];
        Log::info('微收银-易生支付-被扫');
        Log::info($easypay_data);
        $return = $obj->scan_pay($easypay_data); //-1 系统错误 0-其他 1-成功 2-待支付
        if ($return['status'] == '-1') {
            return json_encode([
                'status' => '2',
                'message' => $return['message']
            ]);
        }

        $pay_time = isset($return['data']['wxtimeend']) ? date('Y-m-d H:i:s', strtotime($return['data']['wxtimeend'])): ''; //支付完成时间，格式为yyyyMMddhhmmss，如2009年12月27日9点10分10秒表示为 20091227091010
        $trade_no = $return['data']['wtorderid'] ?? ''; //系统订单号
        $other_no = $return['data']['tradetrace'] ?? ''; //商户订单号（请求原值返回）
        $clearamt = isset($return['data']['clearamt']) ? ($return['data']['clearamt'] / 100): ''; //结算金额，单位分
        $payamt = isset($return['data']['payamt']) ? ($return['data']['payamt'] / 100): ''; //实付金额，单位分

        //支付成功
        if ($return['status'] == '1') {
            $data_update= [
                'trade_no' => $trade_no,
                'other_no' => $other_no,
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '', //credit--信用卡 pcredit--花呗（仅支付宝） debit--借记卡 balance--余额 unknown--未知
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $payamt //用户实际支付
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $ways_type,
                'ways_type_desc' => $ways_type_desc,
                'company' => $company,
                'source_type' => '21000', //返佣来源
                'source_desc' => '易生支付', //返佣来源说明
                'total_amount' => $payamt,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $ways_source,
                'pay_time' => $pay_time,
                'device_id' => $device_id,
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => '1',
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $payamt,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'out_transaction_id' => $out_trade_no,
                    'ways_source' => $ways_source,
                ]
            ]);
        }

        //待支付
        if ($return['status'] == '2') {
            return json_encode([
                'status' => '9',
                'pay_status' => '2',
                'message' => '正在支付',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $payamt,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $ways_source,
                ]
            ]);
        }

        //其他
        if ($return['status'] == '0') {
            return json_encode([
                'status' => '2',
                'pay_status' => 3,
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $payamt,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $ways_source,
                ]
            ]);
        }

    }


    //联动优势 被扫 公共
    public function linkage_pay_public($data_insert, $data)
    {
        $orderType = $data['orderType'];
        $goodsId = $data['goodsId'];
        $title = $data['title'];
        $ways_source_desc = $data['ways_source_desc'];
        $ways_type_desc = $data['ways_type_desc'];
        $code = $data['code'];
        $out_trade_no = $data['out_trade_no'];
        $config_id = $data['config_id'];
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $ways_type = $data['ways_type'];
        $ways_source = $data['ways_source'];
        $company = $data['company'];
        $total_amount = $data['total_amount'];
        $remark = $data['remark'];
        $device_id = $data['device_id'];
        $shop_name = $data['shop_name'];
        $merchant_id = $data['merchant_id'];
        $store_name = $data['store_name'];
        $tg_user_id = $data['tg_user_id'];

        $config = new LinkageConfigController();
        $linkage_config = $config->linkage_config($data['config_id']);
        if (!$linkage_config) {
            return json_encode([
                'status' => '2',
                'message' => '联动配置不存在请检查配置'
            ]);
        }

        $linkage_merchant = DB::table('store_linkages')->where(['store_id' => $store_id])->first();
        if (!$linkage_merchant) {
            return json_encode([
                'status' => '2',
                'message' => '联动商户号不存在'
            ]);
        }

        $out_trade_no = $data['out_trade_no'];

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $ways_type;
        $data_insert['ways_type_desc'] = $ways_type_desc;
        $data_insert['ways_source'] = $ways_source;
        $data_insert['company'] = $company;
        $data_insert['ways_source_desc'] = $ways_source_desc;

        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => '2',
                'message' => '订单未入库'
            ]);
        }

        $obj = new LinkAgePayController();
        $linkageData['acqSpId'] = $linkage_config->mch_id; //代理商编号
        $linkageData['out_trade_no'] = $out_trade_no; //商户订单号
        $linkageData['total_amount'] = $total_amount; //订单金额
        $linkageData['ways_source'] = $ways_source; //订单类型
        $linkageData['authCode'] = $code; //付款码
        $linkageData['backUrl'] = url('/api/linkage/pay_notify_url'); //O,通知地址
        $linkageData['privateKey'] = $linkage_config->privateKey; //私钥
        $linkageData['publicKey'] = $linkage_config->publicKey; //公钥
        $linkageData['store_id'] = $linkage_merchant->merchant_id;
        $linkageData['device_info'] = $device_id;
        
        $return = $obj->scan_pay($linkageData); //-1 系统错误 0-其他 1-成功 2-验签失败 3-支付中 4-交易失败
        //支付成功
        if ($return['status'] == '1') {
//            $out_trade_no = $return['data']['orderNo'] ?? ''; //O,商户订单号
            // $paySeq = $return['data']['paySeq'] ?? ''; //O,支付流水号（条形码），成功返回
            $trade_no = $return['data']['trade_no']; //联动优势的订单号
            $total_amount = $total_amount; //订单金额
            $user_info = '';
            $pay_time = date('Y-m-d H:i:s', time());
            $buyer_pay_amount = $total_amount;
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');

            $update_data = [
                'trade_no' => $trade_no,
                'buyer_id' => $user_info,
                'buyer_logon_id' => '',
                'status' => '1',
                'pay_status' => 1,
                'pay_status_desc' => '支付成功',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount //用户实际支付
            ];
            $this->update_day_order($update_data, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $ways_type,
                'ways_type_desc' => $ways_type_desc,
                'company' => $data_insert['company'],
                'source_type' => '5000', //返佣来源
                'source_desc' => 'linkage', //返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $ways_source,
                'pay_time' => $pay_time,
                'device_id' => $device_id ?? ''
            ];
            if (isset($data_insert['other_no'])) $data['other_no'] = $data_insert['other_no'];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => '1',
                'pay_status' => 1,
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'ways_source' => $ways_source
                ]
            ]);
        } //正在支付
        elseif ($return['status'] == '3') {
            return json_encode([
                'status' => '9',
                'pay_status' => 1,
                'message' => '支付中',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $ways_source,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id
                ]
            ]);
        }
        else {
            return json_encode([
                'status' => '2',
                'pay_status' => 3,
                'message' => $return['message']
            ]);
        }

    }
    
    


    //威富通 被扫 公共
    public function wft_pay_public($data_insert, $data)
    {
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];
        $out_trade_no = $data['out_trade_no'];
        $code = $data['code'];

        $config = new WftPayConfigController();

        $version="v1";
        if(in_array(trim($ways_type),[27101, 27102, 27103, 27104, 27105, 27107])){
            $version="v2";
        }

        $wftpay_config = $config->wftpay_config($data['config_id'],$version);
        if (!$wftpay_config) {
            return json_encode([
                'status' => 2,
                'message' => '威富通配置不存在请检查配置'
            ]);
        }

        $wftpay_merchant = $config->wftpay_merchant($store_id, $store_pid,$version);
        if (!$wftpay_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '威富通商户号不存在'
            ]);
        }

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new WftpayPayController();
        $data['mch_id'] = $wftpay_merchant->mch_id;
        $data['out_trade_no'] = $out_trade_no;
        $data['body'] = $title;
        $data['total_amount'] = $total_amount;
        $data['code'] = $code;
        $data['private_rsa_key'] = $wftpay_config->private_rsa_key;
        $data['public_rsa_key'] = $wftpay_config->public_rsa_key;
        $return = $obj->scan_pay($data); //0-系统错误 1-成功 2-失败
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['transaction_id']; //平台交易号
            $other_no = $return['data']['out_transaction_id']; //第三方订单号
            $pay_time = date('Y-m-d H:i:s', strtotime($return['data']['time_end']));
            $buyer_pay_amount = $return['data']['total_fee']/100; //实收金额，单位为元，两位小数。该金额为本笔交易，商户账户能够实际收到的金额
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');
            $buyer_id = $return['data']['buyer_user_id'] ?? ''; //买家在支付宝的用户id
            $buyer_logon_id = $return['data']['buyer_logon_id'] ?? ''; //买家支付宝账号

            $data_update= [
                'trade_no' => $trade_no,
                'other_no' => $other_no,
                'buyer_id' => $buyer_id,
                'buyer_logon_id' => $buyer_logon_id,
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '27000',//返佣来源
                'source_desc' => '威富通',//返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'out_transaction_id' => $trade_no,
                    'ways_source' => $data['ways_source']
                ]
            ]);
        }
        
        //支付中
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 9,
                'pay_status' => 1,
                'message' => '支付中',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $data['ways_source']
                ]
            ]);
        }

    }
    
    //翼支付
    public function wing_pay_public($data_insert, $data)
    {
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];
        $out_trade_no = $data['out_trade_no'];
        $code = $data['code'];

        $config = new WingConfigController();
        $h_merchant = $config->wing_merchant($store_id, $store_pid);
        if (!$h_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '翼支付商户号不存在'
            ]);
        }

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new \App\Api\Controllers\lianfu\PayController();
        $data1['institutionCode'] = $h_merchant->institutionCode;//平台商商户号
        $data1['merchantNo'] = $h_merchant->merchantNo;//商户号
        $data1['outTradeNo'] = $out_trade_no;//商户订单号
        $data1['tradeAmt'] = bcmul($total_amount, 100);//交易金额
        $data1['mediumNo'] = $data['code'];//条码信息
        $data1['subject'] = '翼支付';//订单主题
        $data1['timeOut'] = 300;//订单超时时间
        $data1['requestDate'] = date('Y-m-d H:i:s', time());//请求时间
        $data1['operator'] = '二维码收款';//操作员
        $data1['goodsInfo'] = '二维码收款';//商品信息
        $data1['terminalCode'] = $store_id;//终端号
        $data1['terminalInfo'] = json_encode(array('terminalId'=>$store_id,'terminalIp'=>$_SERVER['REMOTE_ADDR']));//终端信息
        $return = $obj->scan_pay2($data1);
        
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //支付成功
        if ($return['status'] == 1) {
            $trade_no = $return['data']['result']['bankRequestNo'];
            $other_no = $return['data']['result']['tradeNo'];
            $pay_time = date('Y-m-d H:i:s', time());
            $buyer_pay_amount = $total_amount;
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');
            $buyer_id = $return['data']['buyer_user_id'] ?? '';
            $buyer_logon_id = $return['data']['buyer_logon_id'] ?? '';

            $data_update= [
                'trade_no' => $trade_no,
                'other_no' => $other_no,
                'buyer_id' => $buyer_id,
                'buyer_logon_id' => $buyer_logon_id,
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '27000',//返佣来源
                'source_desc' => '翼支付',//返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'out_transaction_id' => $trade_no,
                    'ways_source' => $data['ways_source']
                ]
            ]);
        }
        
        //支付中
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 9,
                'pay_status' => 2,
                'message' => '支付中',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'ways_source' => $data['ways_source'],
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 3) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $data['ways_source']
                ]
            ]);
        }

    }


    //汇旺财 被扫 公共
    public function hwc_pay_public($data_insert, $data)
    {
        $store_id = $data['store_id'];
        $store_pid = $data['store_pid'];
        $merchant_id = $data['merchant_id'];
        $total_amount = $data['total_amount'];
        $ways_type = $data['ways_type'];
        $store_name = $data['store_name'];
        $config_id = $data['config_id'];
        $desc = $data['ways_type_desc'];
        $title = $data['title'];
        $tg_user_id = $data['tg_user_id'];
        $out_trade_no = $data['out_trade_no'];
        $code = $data['code'];

        $config = new HwcPayConfigController();
        $hwcpay_config = $config->hwcpay_config($data['config_id']);
        if (!$hwcpay_config) {
            return json_encode([
                'status' => 2,
                'message' => '汇旺财配置不存在请检查配置'
            ]);
        }

        $hwcpay_merchant = $config->hwcpay_merchant($store_id, $store_pid);
        if (!$hwcpay_merchant) {
            return json_encode([
                'status' => 2,
                'message' => '汇旺财商户号不存在'
            ]);
        }

        //入库参数
        $data_insert['out_trade_no'] = $out_trade_no;
        $data_insert['ways_type'] = $data['ways_type'];
        $data_insert['ways_type_desc'] = $data['ways_type_desc'];
        $data_insert['company'] = $data['company'];
        $data_insert['ways_source'] = $data['ways_source'];
        $data_insert['ways_source_desc'] = $data['ways_source_desc'];

        $insert_re = $this->insert_day_order($data_insert);
        if (!$insert_re) {
            return json_encode([
                'status' => 2,
                'message' => '订单未入库'
            ]);
        }

        $obj = new HwcpayPayController();
        $data['mch_id'] = $hwcpay_merchant->mch_id;
        $data['out_trade_no'] = $out_trade_no;
        $data['body'] = $title;
        $data['total_amount'] = $total_amount;
        $data['code'] = $code;
        $data['private_rsa_key'] = $hwcpay_config->private_rsa_key;
        $data['public_rsa_key'] = $hwcpay_config->public_rsa_key;
//        Log::info('汇旺财-微收银-被扫-入参');
//        Log::info($data);
        $return = $obj->scan_pay($data); //0-系统错误 1-成功 2-失败
//        Log::info('汇旺财-微收银-被扫');
//        Log::info($return);
        if ($return['status'] == 0) {
            return json_encode([
                'status' => 2,
                'message' => $return['message']
            ]);
        }

        //支付成功
        if ($return['status'] == 1) {
            $trade_no = isset($return['data']['third_order_no']) ? $return['data']['third_order_no'] : $return['data']['transaction_id']; //第三方商户单号，可在支持的商户扫码退款
            $other_no = $return['data']['out_transaction_id']; //第三方订单号
            $pay_time = date('Y-m-d H:i:s', strtotime($return['data']['time_end'])); //支付完成时间，格式为yyyyMMddHHmmss，如2009年12月27日9点10分10秒表示为20091227091010
            $buyer_pay_amount = isset($return['data']['receipt_amount']) ? $return['data']['receipt_amount']: $return['data']['total_fee']; //实收金额，单位为元，两位小数。该金额为本笔交易，商户账户能够实际收到的金额or总金额，以分为单位
            $buyer_pay_amount = number_format($buyer_pay_amount, 2, '.', '');
            $buyer_id = $return['data']['buyer_user_id'] ?? ''; //买家在支付宝的用户id
            $buyer_logon_id = $return['data']['buyer_logon_id'] ?? ''; //买家支付宝账号

            $data_update= [
                'trade_no' => $trade_no,
                'other_no' => $other_no,
                'buyer_id' => $buyer_id,
                'buyer_logon_id' => $buyer_logon_id,
                'status' => '1',
                'pay_status_desc' => '支付成功',
                'pay_status' => 1,
                'payment_method' => '',
                'pay_time' => $pay_time,
                'buyer_pay_amount' => $buyer_pay_amount
            ];
            $this->update_day_order($data_update, $out_trade_no);

            //支付成功后的动作
            $data = [
                'ways_type' => $data['ways_type'],
                'ways_type_desc' => $data['ways_type_desc'],
                'company' => $data_insert['company'],
                'source_type' => '28000',//返佣来源
                'source_desc' => '汇旺财',//返佣来源说明
                'total_amount' => $total_amount,
                'out_trade_no' => $out_trade_no,
                'rate' => $data_insert['rate'],
                'fee_amount' => $data_insert['fee_amount'],
                'merchant_id' => $merchant_id,
                'store_id' => $store_id,
                'user_id' => $tg_user_id,
                'config_id' => $config_id,
                'store_name' => $store_name,
                'ways_source' => $data['ways_source'],
                'pay_time' => $pay_time,
                'device_id' => isset($data['device_id']) ? $data['device_id'] : "",
            ];
            PaySuccessAction::action($data);

            return json_encode([
                'status' => 1,
                'pay_status' => '1',
                'message' => '支付成功',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'pay_time' => $pay_time,
                    'trade_no' => $trade_no,
                    'out_transaction_id' => $trade_no,
                    'ways_source' => $data['ways_source']
                ]
            ]);
        }

        //支付失败
        if ($return['status'] == 2) {
            return json_encode([
                'status' => 2,
                'pay_status' => '3',
                'message' => '支付失败',
                'data' => [
                    'out_trade_no' => $out_trade_no,
                    'ways_type' => $ways_type,
                    'total_amount' => $total_amount,
                    'store_id' => $store_id,
                    'store_name' => $store_name,
                    'config_id' => $config_id,
                    'ways_source' => $data['ways_source']
                ]
            ]);
        }

    }


}
